﻿using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Dapper;
using System.Linq;

namespace DCode.EmailValidator.UI.Domain
{
    public class User
    {
        public int Id { get; set; }
        public string Email { get; set; }
        public string Password { get; set; }
        public DateTime CreatedDate { get; set; }
        public int DailyTransactions { get; set; }

        public static int RegisterUser(string email, string password)
        {
            return 0;
        }

        public static bool CheckUser(string email, string password)
        {
            User currentUser;

            using (var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ValidatorDb"].ConnectionString))
            {
                currentUser = sqlConnection.Query<User>("GetUserByPassword", new { email = email, password = password }, commandType: CommandType.StoredProcedure).FirstOrDefault();
            }

            if (currentUser == null) return false;

            return currentUser.Id > 0;
        }

        public static int GetRemainTransactions(int userId)
        {
            return 0;
        }
    }
}
